package com;

import com.central.scheduler.spi.SchedulerPlugin;
import com.google.common.collect.ImmutableList;
import org.sonatype.aether.artifact.Artifact;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

/**
 * @author Tindy
 * @date 2022/1/21
 * @describe
 */
public class T {
    public static void main(String[] args) throws MalformedURLException {
        List<URL> urls = new ArrayList<>();
        File file = new File("D:\\workspace\\java\\td-data2\\td-scheduler\\scheduler-registry-plugin\\scheduler-registry-zookeeper\\target\\scheduler-registry-zookeeper-0.2.0\\lib\\a.jar");
        urls.add(file.toURI().toURL());
        T t = new T();
        ClassLoader parent = t.getClass().getClassLoader();
        URLClassLoader pluginClassLoader = new URLClassLoader(urls.toArray(new URL[0]), null);
        ServiceLoader<SchedulerPlugin> serviceLoader = ServiceLoader.load(SchedulerPlugin.class, pluginClassLoader);
        List<SchedulerPlugin> plugins = ImmutableList.copyOf(serviceLoader);
        System.out.println(plugins);
    }
}
